package cn.mickey.exchange.util;

import cn.mickey.exchange.domain.exception.ConditionException;
import cn.mickey.exchange.domain.model.UserModel;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UserUtil {

    public static boolean userPasswordVerify(UserModel dbUser, UserModel user){
            try {
                if (RSAUtil.decrypt(dbUser.getUserPassword())
                        .equals(user.getUserPassword())){
                    return true;
                }
            } catch (Exception e) {
                log.info("密码解密失败!");
                e.printStackTrace();
            }
        return false;
    }

    public static String passwordEncrypt(String userPassword){
        //采用RSA加密密码
        String rsaEncryptPassword;
        try {
            rsaEncryptPassword = RSAUtil.encrypt(userPassword);
        } catch (Exception e) {
            throw new ConditionException("密码加密失败!");
        }
        return rsaEncryptPassword;
    }
}
